package xyz.scootaloo.oj.offer

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester

/**
 * @author flutterdash@qq.com
 * @since 2021/4/13 11:14
 */
class P58II {

    private fun reverseLeftWords(s: String, n: Int): String {
        if (n == 0)
            return s
        val size = s.length
        val chars = CharArray(size)
        for (idx in (n) until size)
            chars[idx - n] = s[idx]
        for (idx in 0 until n)
            chars[size - n + idx] = s[idx]
        return String(chars)
    }

    @Test
    fun test0() {
        Tester.createTest(this::testFun)
            .addCase(Parameter("abcdefg", 2), "cdefgab")
            .addCase(Parameter("lrloseumgh", 6), "umghlrlose")
            .testAndShow()
    }

    private fun testFun(p: Parameter): String {
        return reverseLeftWords(p.s, p.n)
    }

    inner class Parameter(
        val s: String,
        val n: Int
    )

}
